﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using giaoxuhaison.Models;

namespace giaoxuhaison.MembershipServices
{
    public class ContactService
    {
        private readonly gxhaisonEntities _dataLocal;

        public ContactService()
        {
            try
            {
                if (_dataLocal == null) _dataLocal = new gxhaisonEntities();
            }
            catch
            {
                _dataLocal = null;
            }
        }

        public MembershipStatus Inserted(ContactModels model)
        {
            try
            {
                Contact data = new Contact();

                data.CustName = model.CustName;
                data.Email = model.Email;
                data.Phone = model.Phone;
                data.Title = model.Title;
                data.Contents = model.Contents;
                data.RequestDate = DateTime.Now;
                data.Notes = "";

                _dataLocal.Contacts.AddObject(data);
                _dataLocal.SaveChanges();
                data = null;

                return MembershipStatus.Success;
            }
            catch
            {
                return MembershipStatus.ErrorConnection;
            }
        }
    }
}